import threading
import win32api
import os
from pubsub import pub

'''
自动打印文档
'''


class PrintThread(threading.Thread):
    def __init__(self, path, piler_no):
        super().__init__()
        self.path = path
        self.piler_no = piler_no

    def run(self) -> None:
        self.print_file()

    def print_file(self):
        path = self.path
        file_type_list = [".钻孔桩成孔质量检查记录.xlsx", ".钻孔桩水下混凝土浇注施工记录.xlsx",
                          ".钻孔桩钻进记录（旋转钻） .xlsx"]
        for file_type in file_type_list:
            file_name = str(self.piler_no) + str(file_type)
            full_path = os.path.join(self.path, file_name)
            if os.path.exists(full_path):
                win32api.ShellExecute(0, "print", full_path, None, ".", 0)
                pub.sendMessage('info_status', message=file_name + "文件打印成功！")
            else:
                pub.sendMessage('info_status', message=file_name + "文件不存在！")
